<?php


namespace app\index\controller;


use think\Db;
use think\Request;

class MicroPay
{
    public function micro_pay(){
        $data = Request::instance()->param();
        $url='https://pay.qcloud.com/cpay/micro_pay';
        $authen_info = array('a'=>array('authen_type'=>1,'authen_code'=>'3A3EB2C286AC78DA325C8125E605B0335E220BB3C77C3C4183E9DFD260950250'));
        $request_content =array('pay_mch_key'=>array(
            'pay_platform'=>1,'out_mch_id'=>'sz01RArHTeMtZSoLbDeG','out_sub_mch_id'=>'sz01R3uNaRrdGB4OsQgk','out_shop_id'=>'sz01Hbo8iSvExbrgqZZC'
        ),'nonce_str'=>'3HJwhkJ64iXYB6Qz8WESQkxAzWJyDxKd','aorder_client'=>array(
            'device_id'=>'335270','terminal_type'=>100,'machine_no'=>'335270','sdk_version'=>'1.6','spbill_create_ip'=>'90.0.0.0'
        ),'pay_content'=>array(
            'total_fee'=>1,'author_code'=>'134656368308544922','out_trade_no'=>'sz01017yeo1576485117571','fee_type'=>'CNY','body'=>'万吉行独立收银支付'
        ));
        $json_request_content = json_encode($request_content);
        $returndata = array('authen_info'=>$authen_info,'request_content'=>$json_request_content);
        return json($returndata);
        $data = array('authen_info'=>$authen_info,'request_content'=>$request_content);
        $res = $this->http_request($url, json($data));
        return $res;
    }

    public function api_test(){
        $data = Request::instance()->param();
        return json($data);
    }

    public function http_request($url, $rawData,$second = 30)
    {
        $ch = curl_init();
        // 设置超时
        $header[] = "Content-type: application/json";
        curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
        curl_setopt($ch, CURLOPT_TIMEOUT, $second);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);//严格校验
        // 设置header
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        // 要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // post提交方式
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($rawData));
        // 运行curl
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
}